package org.nalai.learn2;


import sun.misc.Unsafe;

import java.lang.reflect.Field;

public class Neicun {

    public static void main(String[] args) {
        Unsafe unsafe;

        try {
            Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
            field.setAccessible(true);
            unsafe = (sun.misc.Unsafe) field.get(null);
        } catch (Exception e) {
            throw new AssertionError(e);
        }

        long value = 12345;
        byte size = 1;

        long allocateMemory = unsafe.allocateMemory(size);
        System.out.println(allocateMemory);

        unsafe.putAddress(allocateMemory, value);

        long readValue = unsafe.getAddress(allocateMemory);
        System.out.println("read value : " + readValue);

    }
}
